/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-06-00     YTR       the first version
 */

#define DBG_TAG "rt_pin"
#define DBG_LVL DBG_LOG

#include "all.h"

#define led_pin  GET_PIN(A, 1)
#define key1_pin  GET_PIN(E, 3)
#define key2_pin  GET_PIN(C, 5)

rt_uint8_t led_flag =0;

/* 中断回调函数 */
void led_on(void *args)
{
    LED_Toogie();
}

void led_off(void *args)
{
    LED_Toogie();
}

void Pin_Init(void){
    rt_pin_mode(led_pin, PIN_MODE_OUTPUT);
    rt_pin_mode(key1_pin, PIN_MODE_INPUT_PULLUP);
    rt_pin_mode(key2_pin, PIN_MODE_INPUT_PULLUP);
    rt_pin_attach_irq(key1_pin, PIN_IRQ_MODE_FALLING , led_on, RT_NULL);/* 绑定中断，下降沿模式，回调函数名为led_on */
    rt_pin_attach_irq(key2_pin, PIN_IRQ_MODE_FALLING , led_off, RT_NULL);
    rt_pin_irq_enable(key1_pin, PIN_IRQ_ENABLE);/* 使能中断 */
    rt_pin_irq_enable(key2_pin, PIN_IRQ_ENABLE);
}


void LED_Toogie(void){
    if(led_flag==0){
        rt_pin_write(led_pin, PIN_HIGH);
    }
    else{
        rt_pin_write(led_pin, PIN_LOW);
    }
    led_flag =!led_flag;
}

